import fnmatch


class AntPathMatcher:
    @staticmethod
    def match(url: str, pattern: str) -> bool:
        """
        匹配

        :param url: url地址，例如：/api/demo
        :param pattern: 匹配规则， 例如：/api/**
        :return:
        """
        return fnmatch.fnmatch(url, pattern)

    @staticmethod
    def batch_match(url: str, patterns: list) -> bool:
        """
        批量匹配

        :param url: url地址，例如：/api/demo
        :param patterns: 匹配规则， 例如：['/api/**','/**/noToken']
        :return:
        """
        return any(AntPathMatcher.match(url, pattern) for pattern in patterns)


matcher = AntPathMatcher()
